package com.yymmarket.forum.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


/**
 * 
 *  @author LeiHongyun  2010-10-27 09:49:54
 *
 */
public class UtilTools {

	
	
	public static void process(Object bea) {
		
		Connection conn = null;  
		Statement stat = null;  
		ResultSet rs = null;
		
		try {
			Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
			System.out.println(conn == null);
			String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=yymmarket";  
			String user="sa";
			String password="sa";
			
			conn = DriverManager.getConnection(url, user, password);
			
			stat = conn.createStatement();
			
			//String sql = "insert into yymmarket_luck values(?,?,?,?,?,?,?,?,?,?,?)";
			String sql = "insert into yymmarket_psychology_answer values(?,?,?)";
			PreparedStatement ps = conn.prepareStatement(sql);
			//PsychologyAnswerBean bean = (PsychologyAnswerBean)bea;
			
		//	ps.setString(1, bean.getAnswer());
			//ps.setString(2, bean.getExplanation());
		//	ps.setInt(3, bean.getPsychologyId());
//			ps.setString(3, bean.getLuckSynthesis());
//			ps.setString(4, bean.getLuckLove());
//			ps.setString(5, bean.getLuckJob());
//			ps.setString(6, bean.getLuckFinace());
//			ps.setString(7, bean.getLuckHealth());
//			ps.setString(8, bean.getLuckColor());
//			ps.setInt(9, bean.getLuckNum());
//			ps.setString(10, bean.getLuckMate());
//			ps.setString(11, bean.getLuckAppraise());
			
			
			ps.executeUpdate();
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try {  
				if(rs != null)   
					rs.close();  
					if(stat != null)  
					stat.close();  
						if(conn != null)  
							conn.close();  
						} catch (SQLException e2) {  
							e2.printStackTrace();  
					}  
		}
		
	}
	
	public static void main(String args[]){
		File aFile = new File("D:/data.txt");
		BufferedReader bReader = null;
		FileInputStream inFile = null;
		String s = null;
		try{

		inFile = new FileInputStream(aFile);

		} catch(FileNotFoundException e) {e.printStackTrace();}

		bReader = new BufferedReader(new InputStreamReader(inFile));

		try {

		while(true) {

		s = bReader.readLine();
		if(s == null) break;
		String[] strs = s.split(",");
		//PsychologyAnswerBean bean = new PsychologyAnswerBean();
		//bean.setPsychologyId(Integer.parseInt(strs[1].trim()));
		//bean.setAnswer(strs[2].replace("'", "").trim());
		//bean.setExplanation(strs[3].replace("'", "").trim());
//		PsychologyBean bean = new PsychologyBean();
//		bean.setId(Integer.parseInt(strs[0].trim()));
//		bean.setPsychologyTitle(strs[1].replace("'", "").trim());
//		bean.setPsychologyContent(strs[2].replace("'", "").trim());
//		LuckBean luckBean = new LuckBean();
//		luckBean.setLuckId(Integer.parseInt(strs[0].trim()));
//		luckBean.setLuckDay(Integer.parseInt(strs[1].trim()));
//		luckBean.setLuckConstellation(strs[2].replace("'", "").trim());
//		luckBean.setLuckSynthesis(strs[3].replace("'", "").trim());
//		luckBean.setLuckLove(strs[4].replace("'", "").trim());
//		luckBean.setLuckJob(strs[5].replace("'", "").trim());
//		luckBean.setLuckFinace(strs[6].replace("'", "").trim());
//		luckBean.setLuckHealth(strs[7].replace("'", "").trim());
//		luckBean.setLuckColor(strs[8].replace("'", "").trim());
//		luckBean.setLuckNum(Integer.parseInt(strs[9].trim()));
//		luckBean.setLuckMate(strs[10].replace("'", "").trim());
//		luckBean.setLuckAppraise(strs[11].replace("'", "").trim());
//		
		//process(bean);
//		for (String str : strs) {
//			System.out.println(str.replace("'","").trim());
//		}
		
		//System.out.println(s);

		}
		} catch(IOException e) {e.printStackTrace();}

		System.exit(0);
	}
}
